package pacman.actors;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.state.BasicGameState;

import pacman.base.Body;
import pacman.base.Entity;
import pacman.base.Level;
import pacman.map.Map;
import pacman.util.Collider;

public class Gem extends Body {
    private Image image;
    private boolean toRemove = false;

    public Gem(Role role, Shape shape, Image image) {
		super(role, shape);
		this.image = image;
    }
    //------------------------------------------------//
    public void render(BasicGameState game, Graphics g) {
    	g.drawImage(this.image, getX(), getY());
    }

    public void update(GameContainer game, int delta) {
		if (!toRemove) {
		    Player player = Map.getPlayer();
		    Collider.testAndAlert(player, this);
		}
    }
    //------------------------------------------------//
    public void addToLevel(Level l) {
    	l.add(this);
    }

    public Role getRole() {
    	return Role.GOLD;
    }

    public void onCollision(Entity obstacle) {
		if (obstacle.getRole().equals(Entity.Role.PLAYER)) {
		    toRemove = true;
		}
    }

    public void removeFromLevel(Level l) {
    	l.remove(this);
    }

    public boolean isToRemove() {
    	return toRemove;
    }

}
